package com.permissionmanager.exception;

import com.permissionmanager.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局监控异常
 *
 */

@ControllerAdvice
public class GlobalException {

    // 返回一个Result类型的异常
    @ExceptionHandler(ServiceException.class) // 捕获异常
    @ResponseBody // 把Result对象转化为join对象
    public Result serviceException(ServiceException e) {
        return Result.error(e.getCODE(),e.getMessage());
    }
}